package com.topc.others.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.topc.base.exception.Asserts;
import com.topc.others.mapper.ArticleContentMapper;
import com.topc.others.model.po.ArticleContent;
import com.topc.others.model.po.ArticleInfo;
import com.topc.others.service.IArticleContentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 文章内容 服务实现类
 * </p>
 *
 * @author Gogoing
 */
@Slf4j
@Service
public class ArticleContentServiceImpl extends ServiceImpl<ArticleContentMapper, ArticleContent> implements IArticleContentService {

    @Override
    public Long saveContentToId(String content) {
        ArticleContent articleContent = new ArticleContent();
        articleContent.setContent(content);
        boolean save = this.save(articleContent);
        if (!save) Asserts.fail("保存失败");
        return articleContent.getId();
    }

    @Override
    public void saveContentById(Long contentId, String content) {
        LambdaUpdateWrapper<ArticleContent> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ArticleContent::getId, contentId);
        updateWrapper.set(ArticleContent::getContent,content);
        boolean update = this.update(updateWrapper);
        if (!update)Asserts.fail("内容更新失败");
    }

    @Override
    public void deleteInfoById(Long contentId) {
        LambdaQueryWrapper<ArticleContent> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ArticleContent::getId, contentId);
        boolean removeContent = this.remove(lambdaQueryWrapper);
        if (!removeContent)Asserts.fail("删除失败");
    }

}
